<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<html>
<head>
<title>ASP.NET Objects</title>
<script language="VB" runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
	if not Page.IsPostBack then
		BindData
	end if
End Sub
Sub BindData()
Dim strConn as string = _
ConfigurationSettings.appSettings("defaultcon")
Dim strSQL as string = "Select EmployeeID," & _ 
 " FirstName, LastName, Title from Employees"
  Dim myConn As New SQLConnection(strConn)
  Dim myDataReader as SQLDataReader
  Dim Cmd as New SQLCommand(strSQL , myConn)
  myConn.Open()
  myDataReader=Cmd.ExecuteReader( _
	system.data.CommandBehavior.CloseConnection)
  MyDataGrid.DataSource = myDataReader
  MyDataGrid.DataBind()
  myConn.close
End Sub
</script>
</head>
<body><div align="center">
<h2>DataReader and Command</h2>
<form runat="server" method="post">
<asp:Datagrid runat="server"
	Id="MyDataGrid"
	GridLines="Both"
	cellpadding="0"
	cellspacing="0"
	Headerstyle-BackColor="gray"
	Headerstyle-Font-Name="Arial"
	Headerstyle-Font-Size="10"
        	Headerstyle-Font-Bold="True"
	BackColor="#FFFFFF"
	Font-Name="Arial"
	Font-Size="10"
	BorderColor="Black"	
	AutogenerateColumns="False">
	<Columns>		
		<asp:BoundColumn 
			DataField="EmployeeID" 
			HeaderText="&nbsp;EmployeeID&nbsp;" 
			ReadOnly="True">
		</asp:BoundColumn>
		<asp:BoundColumn 
			DataField="FirstName" 
			HeaderText="&nbsp;FirstName&nbsp;">
		</asp:BoundColumn>
		<asp:BoundColumn 
			DataField="LastName" 
			HeaderText="&nbsp;LastName&nbsp;">
		</asp:BoundColumn>
		<asp:BoundColumn 
			DataField="Title" 
			HeaderText="&nbsp;Title&nbsp;">
		</asp:BoundColumn>
	</Columns>
</asp:DataGrid>
</form>
</div>
</body>
</html>
